package com.pangyangyang.elasticsearch.plugin.river;

import java.util.Map;

/**
 * Created by yangwang on 2015/1/22.
 */
public class MessageRiverSettings {

    private Map<String, Object> settings;

    public MessageRiverSettings(Map<String, Object> settings) {
        this.settings = settings;
    }

    public Object getObject(String key){
        Object object = this.settings.get(key);

        return object;
    }

    public String getString(String key){
        Object object = getObject(key);
        if(object == null){
            return "";
        }
        return object.toString();
    }

    public int getInt(String key, int defaultValue) throws NumberFormatException{
        String object = getString(key);
        if(object == ""){
            return defaultValue;
        }
        return Integer.valueOf(object);
    }

    public boolean getBoolean(String key, boolean defaultValue) throws NumberFormatException{
        String object = getString(key);
        if(object == ""){
            return defaultValue;
        }
        return Boolean.valueOf(object);
    }
}
